package lg.iu.transforms.tiledata;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;

import lg.iu.ClassHooks;
import lg.iu.FieldHooks;
import wolf.iu.framework.ClassContainer;
import wolf.iu.framework.ClassesHandler;
import wolf.iu.framework.HooksList;
import wolf.iu.framework.hooks.AbstractClassHookEnum;
import wolf.iu.framework.hooks.DependencyTransform;
import wolf.iu.framework.hooks.HookState;

public class TiledataGetterTransform extends DependencyTransform {

    @Override
    public HookState execute(final ClassesHandler ch, final ClassContainer cc,
            final HooksList hooks) {
        
        final String tdName = hooks.getHook(ClassHooks.TileData).getFullOldName();
        
        for (final Object o : cc.getNode().fields) {
            final FieldNode fn = (FieldNode) o;
            if (fn.desc.equals("[L" + tdName + ";")) {
                hooks.setFieldHook(ClassHooks.Client, FieldHooks.GetTileData,
                        new FieldInsnNode(Opcodes.GETSTATIC, cc.getNode().name, fn.name, fn.desc));
                return HookState.Found;
            }
        }
        
        
        return HookState.WrongClass;
    }

    @Override
    public AbstractClassHookEnum dependency() {
        return ClassHooks.TileData;
    }

}
